package sol.leetcode;

import java.util.Arrays;

/**
 * Remove Duplicates from Sorted Array II
 */
public class Issue080 {
    public int removeDuplicates(int[] nums) {
        int j = -1;
        for (int i = 0; i < nums.length; ++i) {
            if (i >= 2 && nums[j - 1] == nums[i])
                continue;
            else
                nums[++j] = nums[i];
        }
        return j+1;
    }

    public static void main(String[] args) {
        int nums[] = {};
        Issue080 sol = new Issue080();
        int n = sol.removeDuplicates(nums);
        System.out.println(n);
        System.out.println(Arrays.toString(nums));
    }
}
